package indi.zhang.rabbitlistener.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.support.ConsumerTagStrategy;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Configuration
public class RabbitConfig {

    /**
     * 交换机
     */
    public static final String CANAL_EXCHANGE = "canal_exchange";
    /**
     * 队列
     */
    public static final String OPERATION_LOG_QUEUE = "simple_operation_log";
    public static final String EXCEPTION_LOG_QUEUE = "simple_exception_log";

    /**
     * 自动创建交换机
     */
    @Bean
    public DirectExchange canalExchange() {
        return new DirectExchange(CANAL_EXCHANGE);
    }

    /**
     * 自动创建队列
     */
    @Bean
    public Queue operationLogQueue() {
        return new Queue(OPERATION_LOG_QUEUE);
    }
    @Bean
    public Queue exceptionLogQueue() {
        return new Queue(EXCEPTION_LOG_QUEUE);
    }

    /**
     * 自己将队列绑定到交换机，路由键使用队列名
     */
    @Bean
    public Binding operationLogBinding() {
        return BindingBuilder.bind(operationLogQueue()).to(canalExchange()).withQueueName();
    }
    @Bean
    public Binding exceptionLogBinding() {
        return BindingBuilder.bind(exceptionLogQueue()).to(canalExchange()).withQueueName();
    }

}
